import time

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from utils import *


class TestBrowser:
    def setup(self):
        desired_caps = {
            'platformName': 'Android',
            'platformVersion': '6.0',
            'deviceName': '192.168.57.101:5555',
            'resetKeyBoard': True,
            'unicodeKeyboard': True,
            'noReset': True,
            'automationName': 'Uiautomator2',
            # "browser": "Browser",
            "appPackage": "com.android.browser",
            "appActivity": ".BrowserActivity"
        }

        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
        self.driver.implicitly_wait(5)



    def teardown(self):
        self.driver.quit()

    def test_browser(self):
        print(self.driver.contexts)
        self.driver.get('https://www.baidu.com')
        self.driver.switch_to.context(self.driver.contexts[-1])
        time.sleep(5)
        self.driver.find_element(By.ID, 'index-kw').click()
        time.sleep(5)
        self.driver.find_element(By.ID, 'index-kw').send_keys('python')
        time.sleep(5)
        self.driver.find_element(By.ID, 'index-bn').click()

        # self.driver.get('https://baidu.com')
        # print(self.driver.contexts)
        # self.driver.switch_to.context(self.driver.contexts[-1])
        # get_element(self.driver, (By.ID, 'index-kw')).send_keys('python')
        # get_element(self.driver, (By.ID, 'index-bn')).click()

        time.sleep(8)




